package com.bdth.weget.net.thread;

import com.bdth.weget.net.base.SessionData;
import com.bdth.weget.net.bean.ByteMessage;
import com.bdth.weget.util.DateUtil;
import com.bdth.weget.util.LogsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ByteLogRunnable implements Runnable{
    private Logger logger = LoggerFactory.getLogger(ByteLogRunnable.class);

    @Override
    public void run() {
        while(true){
            ByteMessage bytes = null;
            if(SessionData.BYTEMESSAGE.size()<1){
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    logger.error("ByteLogRunnable Sleep Error>>>>" + e.getMessage());
                }
            }else{
                bytes = SessionData.BYTEMESSAGE.poll();
                //写入文件名称
                String file = DateUtil.today()  + ".log";
                LogsUtil.writeLog(file, "[" + DateUtil.now2str() + "]" + bytes.toString() + "\r\n");
            }
        }
    }
}
